var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/table/hook/useAutoScroll.ts
var useAutoScroll_exports = {};
__export(useAutoScroll_exports, {
  useAutoScroll: () => useAutoScroll
});
module.exports = __toCommonJS(useAutoScroll_exports);
var import_react = require("react");
function useAutoScroll({ table, scrollbar }) {
  const _ref = (0, import_react.useRef)({ raf: null, iT: null });
  const { autoScroll } = table.props;
  (0, import_react.useEffect)(() => {
    const container = table.outRef.current._outerRef;
    if (autoScroll && scrollbar.vertical) {
      const rIc = window.requestIdleCallback || window.setTimeout;
      const [clear, exec, delayExec] = [
        () => {
          if (_ref.current.iT) {
            clearTimeout(_ref.current.iT);
            _ref.current.iT = null;
          }
          if (_ref.current.raf) {
            cancelAnimationFrame(_ref.current.raf);
            _ref.current.raf = null;
          }
        },
        () => {
          _ref.current.raf = requestAnimationFrame(() => {
            rIc(() => {
              var _a;
              (_a = table.outRef.current) == null ? void 0 : _a.scrollLeftAndTop({ top: 1 }, ({ top }) => {
                var _a2;
                top && ((_a2 = table.outRef.current) == null ? void 0 : _a2.scrollTo({ scrollTop: 0 }));
                _ref.current.raf && exec();
              });
            });
          });
        },
        () => {
          clear();
          _ref.current.iT = setTimeout(exec, 1e3);
        }
      ];
      delayExec();
      container.addEventListener("mouseenter", clear);
      container.addEventListener("mouseleave", delayExec);
      return () => {
        clear();
        container.addEventListener("mouseenter", clear);
        container.addEventListener("mouseleave", delayExec);
      };
    }
  }, [scrollbar.vertical, autoScroll]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useAutoScroll
});
